package top.wu2020.lazy.ws.chat.infrastructure.persistence;

import top.wu2020.lazy.ws.chat.infrastructure.entity.MailCodeRecordsDO;
import top.wu2020.lazy.ws.chat.infrastructure.converter.MailCodeRecordsConverter;
import top.wu2020.lazy.ws.chat.infrastructure.mapper.MailCodeRecordsMapper;
import top.wu2020.lazy.ws.chat.domain.model.mail.code.records.MailCodeRecordsRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import top.wu2020.lazy.ws.chat.domain.model.mail.code.records.MailCodeRecords;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe 邮箱验证码记录 
 *
 * @author Jia wei Wu
 * @date 2024/05/27 09:30 上午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class MailCodeRecordsRepositoryImpl  implements  MailCodeRecordsRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增邮箱验证码记录
     *
     * @param mailCodeRecords 新增邮箱验证码记录     
     * @return {@link Result<MailCodeRecords>} 邮箱验证码记录新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<MailCodeRecords> story(MailCodeRecords mailCodeRecords) {
        MailCodeRecordsDO mailCodeRecordsDO = MailCodeRecordsConverter.INSTANCE.fromMailCodeRecords(mailCodeRecords);
        lazyLambdaStream.upsert(mailCodeRecordsDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增邮箱验证码记录
     *
     * @param mailCodeRecordsList 批量新增邮箱验证码记录     
     * @return {@link Result<List<MailCodeRecords>>} 邮箱验证码记录新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<List<MailCodeRecords>> batchStory(List<MailCodeRecords> mailCodeRecordsList) {
        List<MailCodeRecordsDO> mailCodeRecordsDOList = mailCodeRecordsList.stream().map(MailCodeRecordsConverter.INSTANCE::fromMailCodeRecords).collect(Collectors.toList());
        lazyLambdaStream.upsert(mailCodeRecordsDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个邮箱验证码记录
     *
     * @param mailCodeRecords 查询单个邮箱验证码记录     
     * @return {@link Result<MailCodeRecords>} 邮箱验证码记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<MailCodeRecords> findOne(MailCodeRecords mailCodeRecords) {
        MailCodeRecordsDO mailCodeRecordsDO = MailCodeRecordsConverter.INSTANCE.fromMailCodeRecords(mailCodeRecords);
        MailCodeRecords mailCodeRecordsOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(mailCodeRecordsDO), MailCodeRecords.class);
        return ResultFactory.successOf(mailCodeRecordsOne);
    }

    /**
     * describe 查询多个邮箱验证码记录
     *
     * @param mailCodeRecords 查询多个邮箱验证码记录     
     * @return {@link Result<List<MailCodeRecords>>} 邮箱验证码记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<List<MailCodeRecords>> findList(MailCodeRecords mailCodeRecords) {
        MailCodeRecordsDO mailCodeRecordsDO = MailCodeRecordsConverter.INSTANCE.fromMailCodeRecords(mailCodeRecords);
        List<MailCodeRecords> mailCodeRecordsList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(mailCodeRecordsDO), MailCodeRecords.class);
        return ResultFactory.successOf(mailCodeRecordsList);
    }

    /**
     * describe 分页查询多个邮箱验证码记录
     *
     * @param size 当前页数
     * @param current 当前页
     * @param mailCodeRecords 分页查询多个邮箱验证码记录     
     * @return {@link Result<LazyPage<MailCodeRecords>>} 分页邮箱验证码记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<LazyPage<MailCodeRecords>> findPage(int size,int current,MailCodeRecords mailCodeRecords) {
        MailCodeRecordsDO mailCodeRecordsDO = MailCodeRecordsConverter.INSTANCE.fromMailCodeRecords(mailCodeRecords);
        LazyPage<MailCodeRecords> lazyPage = new LazyPage<>(current,size);
        LazyPage<MailCodeRecords> mailCodeRecordsLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(mailCodeRecordsDO),lazyPage, MailCodeRecords.class);
        return ResultFactory.successOf(mailCodeRecordsLazyPage);
    }

    /**
     * describe 删除邮箱验证码记录
     *
     * @param mailCodeRecords 删除邮箱验证码记录     
     * @return {@link Result<MailCodeRecords>} 邮箱验证码记录     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<MailCodeRecords> remove(MailCodeRecords mailCodeRecords) {
        MailCodeRecordsDO mailCodeRecordsDO = MailCodeRecordsConverter.INSTANCE.fromMailCodeRecords(mailCodeRecords);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(mailCodeRecordsDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在邮箱验证码记录
     *
     * @param mailCodeRecords 邮箱验证码记录领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/05/27 09:30 上午
     **/

    @Override
    public Result<Boolean> exists(MailCodeRecords mailCodeRecords) {
        MailCodeRecordsDO mailCodeRecordsDO = MailCodeRecordsConverter.INSTANCE.fromMailCodeRecords(mailCodeRecords);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(mailCodeRecordsDO));
        return ResultFactory.successOf(exists);
    }

}